package com.example.auth.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.auth.config.ResultUtil;
import com.example.auth.domain.DataNodeConfig;
import com.example.auth.domain.vo.DataNodeConfigVo;
import com.example.auth.service.DataNodeConfigService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/node")
public class DataNodeController {

    @Autowired
    private DataNodeConfigService service;

    @GetMapping("/page")
    public JSONObject page(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                           @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                           @RequestParam("nodeName")String nodeName) {
        IPage<DataNodeConfig> page=service.page(pageNum,pageSize,nodeName);
        return ResultUtil.successInfo(page);
    }

    @PostMapping("/saveorupdate")
    public JSONObject saveorupdate(@RequestBody @Validated DataNodeConfigVo vo) {
        DataNodeConfig config = new DataNodeConfig();
        BeanUtils.copyProperties(vo, config);
        config.setIsDeleted(0);
        service.saveOrUpdate(config);
        return ResultUtil.successInfo("操作成功");
    }


}
